Index: mod/assignment/view.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/view.php,v
retrieving revision 1.52
diff -u -r1.52 view.php
--- mod/assignment/view.php	28 Apr 2010 02:47:25 -0000	1.52
+++ mod/assignment/view.php	20 Sep 2010 03:50:13 -0000
@@ -3,6 +3,7 @@
 require_once("../../config.php");
 require_once("lib.php");
 require_once($CFG->libdir . '/completionlib.php');
+require_once($CFG->libdir . '/plagiarismlib.php');
 
 $id = optional_param('id', 0, PARAM_INT);  // Course Module ID
 $a  = optional_param('a', 0, PARAM_INT);   // Assignment ID
Index: mod/assignment/renderer.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/renderer.php,v
retrieving revision 1.8
diff -u -r1.8 renderer.php
--- mod/assignment/renderer.php	20 Sep 2010 03:43:47 -0000	1.8
+++ mod/assignment/renderer.php	20 Sep 2010 03:50:13 -0000
@@ -66,8 +66,9 @@
         foreach ($dir['files'] as $file) {
             $filename = $file->get_filename();
             $icon = mimeinfo("icon", $filename);
+            $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
             $image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
-            $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$file->portfoliobutton.'</div></li>';
+            $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
         }
 
         $result .= '</ul>';
Index: mod/assignment/submissions.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/submissions.php,v
retrieving revision 1.52
diff -u -r1.52 submissions.php
--- mod/assignment/submissions.php	28 Apr 2010 02:47:25 -0000	1.52
+++ mod/assignment/submissions.php	20 Sep 2010 03:50:13 -0000
@@ -2,6 +2,7 @@
 
 require_once("../../config.php");
 require_once("lib.php");
+require_once($CFG->libdir.'/plagiarismlib.php');
 
 $id   = optional_param('id', 0, PARAM_INT);          // Course module ID
 $a    = optional_param('a', 0, PARAM_INT);           // Assignment ID
Index: mod/assignment/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/lib.php,v
retrieving revision 1.496
diff -u -r1.496 lib.php
--- mod/assignment/lib.php	20 Sep 2010 01:42:28 -0000	1.496
+++ mod/assignment/lib.php	20 Sep 2010 03:50:13 -0000
@@ -207,6 +207,7 @@
         echo $OUTPUT->box_start('generalbox boxaligncenter', 'intro');
         echo format_module_intro('assignment', $this->assignment, $this->cm->id);
         echo $OUTPUT->box_end();
+        plagiarism_print_disclosure($this->cm->id);
     }
 
     /**
@@ -1096,6 +1097,7 @@
                         self::FILTER_REQUIRE_GRADING => get_string('requiregrading', 'assignment'));
 
         $updatepref = optional_param('updatepref', 0, PARAM_INT);
+        plagiarism_update_status($this->course, $this->cm);
 
         if (isset($_POST['updatepref'])){
             $perpage = optional_param('perpage', 10, PARAM_INT);
@@ -1873,6 +1875,8 @@
                     $button->set_format_by_file($file);
                     $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
                 }
+                $output .= plagiarism_get_links(array('userid'=>$userid, 'file'=>$file, 'cmid'=>$this->cm->id, 'course'=>$this->course, 'assignment'=>$this->assignment));
+                $output .= '<br />';
             }
             if (count($files) > 1  && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
                 $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php');
Index: lib/moodlelib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v
retrieving revision 1.1467
diff -u -r1.1467 moodlelib.php
--- lib/moodlelib.php	19 Sep 2010 14:02:56 -0000	1.1467
+++ lib/moodlelib.php	20 Sep 2010 03:50:12 -0000
@@ -6917,6 +6917,7 @@
             'notes'       => 'notes',
             'pagetype'    => NULL,
             'pix'         => NULL,
+            'plagiarism'  => 'plagiarism',
             'portfolio'   => 'portfolio',
             'publish'     => 'course/publish',
             'question'    => 'question',
@@ -6973,6 +6974,7 @@
                       'portfolio'     => 'portfolio',
                       'qtype'         => 'question/type',
                       'qformat'       => 'question/format',
+                      'plagiarism'    => 'plagiarism',
                       'theme'         => 'theme'); // this is a bit hacky, themes may be in dataroot too
 
         $mods = get_plugin_list('mod');
Index: lib/cronlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/cronlib.php,v
retrieving revision 1.2
diff -u -r1.2 cronlib.php
--- lib/cronlib.php	3 Sep 2010 18:14:57 -0000	1.2
+++ lib/cronlib.php	20 Sep 2010 03:50:11 -0000
@@ -116,6 +116,10 @@
     }
     mtrace('Finished blocks');
 
+    //now do plagiarism checks
+    require_once($CFG->libdir.'/plagiarismlib.php');
+    plagiarism_cron();
+
     mtrace("Starting quiz reports");
     if ($reports = $DB->get_records_select('quiz_report', "cron > 0 AND ((? - lastcron) > cron)", array($timenow))) {
         foreach ($reports as $report) {
Index: lib/adminlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/adminlib.php,v
retrieving revision 1.501
diff -u -r1.501 adminlib.php
--- lib/adminlib.php	17 Sep 2010 10:27:31 -0000	1.501
+++ lib/adminlib.php	20 Sep 2010 03:50:11 -0000
@@ -6552,6 +6552,92 @@
         return highlight($query, $return);
     }
 }
+/**
+ * Special class for plagiarism administration.
+ *
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class admin_setting_manageplagiarism extends admin_setting {
+/**
+ * Calls parent::__construct with specific arguments
+ */
+    public function __construct() {
+        $this->nosave = true;
+        parent::__construct('plagiarismui', get_string('plagiarismsettings', 'plagiarism'), '', '');
+    }
+
+    /**
+     * Always returns true
+     *
+     * @return true
+     */
+    public function get_setting() {
+        return true;
+    }
+
+    /**
+     * Always returns true
+     *
+     * @return true
+     */
+    public function get_defaultsetting() {
+        return true;
+    }
+
+    /**
+     * Always returns '' and doesn't write anything
+     *
+     * @return string Always returns ''
+     */
+    public function write_setting($data) {
+    // do not write any setting
+        return '';
+    }
+
+    /**
+     * Return XHTML to display control
+     *
+     * @param mixed $data Unused
+     * @param string $query
+     * @return string highlight
+     */
+    public function output_html($data, $query='') {
+        global $CFG, $OUTPUT;
+
+        // display strings
+        $txt = get_strings(array('settings', 'name'));
+
+        $plagiarismplugins = get_plugin_list('plagiarism');
+        if (empty($plagiarismplugins)) {
+            return get_string('nopluginsinstalled', 'plagiarism');
+        }
+
+        $return = $OUTPUT->heading(get_string('availableplugins', 'plagiarism'), 3, 'main');
+        $return .= $OUTPUT->box_start('generalbox authsui');
+
+        $table = new html_table();
+        $table->head  = array($txt->name, $txt->settings);
+        $table->align = array('left', 'center');
+        $table->data  = array();
+        $table->attributes['class'] = 'manageplagiarismtable generaltable';
+
+        // iterate through auth plugins and add to the display table
+        $authcount = count($plagiarismplugins);
+        foreach ($plagiarismplugins as $plugin => $dir) {
+            if (file_exists($dir.'/settings.php')) {
+                $displayname = "<span>".get_string($plugin, 'plagiarism_'.$plugin)."</span>";
+                // settings link
+                $settings = "<a href=\"$CFG->wwwroot/plagiarism/$plugin/settings.php\">{$txt->settings}</a>";
+                // add a row to the table
+                $table->data[] =array($displayname, $settings);
+            }
+        }
+        $return .= html_writer::table($table);
+        $return .= get_string('configplagiarismplugins', 'plagiarism');
+        $return .= $OUTPUT->box_end();
+        return highlight($query, $return);
+    }
+}
 
 /**
  * Special class for overview of external services
Index: admin/settings/subsystems.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/settings/subsystems.php,v
retrieving revision 1.9
diff -u -r1.9 subsystems.php
--- admin/settings/subsystems.php	25 Jun 2010 17:21:17 -0000	1.9
+++ admin/settings/subsystems.php	20 Sep 2010 03:50:09 -0000
@@ -39,4 +39,6 @@
     $optionalsubsystems->add(new admin_setting_configcheckbox('enableavailability',
         get_string('enableavailability','condition'),
         get_string('configenableavailability','condition'), 0));
+
+    $optionalsubsystems->add(new admin_setting_configcheckbox('enableplagiarism', get_string('enableplagiarism','plagiarism'), get_string('configenableplagiarism','plagiarism'), 0));
 }
Index: admin/settings/plugins.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/settings/plugins.php,v
retrieving revision 1.86
diff -u -r1.86 plugins.php
--- admin/settings/plugins.php	16 Sep 2010 04:21:52 -0000	1.86
+++ admin/settings/plugins.php	20 Sep 2010 03:50:09 -0000
@@ -376,7 +376,17 @@
         }
     }
 }
-
+if ($hassiteconfig && !empty($CFG->enableplagiarism)) {
+    $ADMIN->add('modules', new admin_category('plagiarism', get_string('plagiarism', 'plagiarism')));
+    $temp = new admin_settingpage('plagiarismsettings', get_string('plagiarismsettings', 'plagiarism'));
+    $temp->add(new admin_setting_manageplagiarism());
+    $ADMIN->add('plagiarism', $temp);
+    foreach (get_plugin_list('plagiarism') as $plugin => $plugindir) {
+        if (file_exists($plugindir.'/settings.php')) {
+            $ADMIN->add('plagiarism', new admin_externalpage('plagiarism'.$plugin, get_string($plugin, 'plagiarism_'.$plugin), "$CFG->wwwroot/plagiarism/$plugin/settings.php", 'moodle/site:config'));
+        }
+    }
+}
 $ADMIN->add('reports', new admin_externalpage('comments', get_string('comments'), $CFG->wwwroot.'/comment/', 'moodle/site:viewreports'));
 /// Now add reports
 
Index: mod/assignment/type/uploadsingle/assignment.class.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/type/uploadsingle/assignment.class.php,v
retrieving revision 1.74
diff -u -r1.74 assignment.class.php
--- mod/assignment/type/uploadsingle/assignment.class.php	2 Sep 2010 09:49:04 -0000	1.74
+++ mod/assignment/type/uploadsingle/assignment.class.php	20 Sep 2010 03:50:13 -0000
@@ -43,6 +43,8 @@
                     $mimetype = $file->get_mimetype();
                     $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename);
                     $output .= '<a href="'.$path.'" ><img class="icon" src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" alt="'.$mimetype.'" />'.s($filename).'</a><br />';
+                    $output .= plagiarism_get_links(array('userid'=>$userid, 'file'=>$file, 'cmid'=>$this->cm->id, 'course'=>$this->course, 'assignment'=>$this->assignment));
+                    $output .='<br/>';
                 }
             }
         }
@@ -264,6 +266,9 @@
         $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
         $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $choices);
         $mform->setDefault('maxbytes', $CFG->assignment_maxbytes);
+
+        $course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
+        plagiarism_get_form_elements_module($mform, $course_context);
     }
 
     function portfolio_exportable() {
Index: mod/assignment/type/upload/assignment.class.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/assignment/type/upload/assignment.class.php,v
retrieving revision 1.130
diff -u -r1.130 assignment.class.php
--- mod/assignment/type/upload/assignment.class.php	17 Sep 2010 02:52:24 -0000	1.130
+++ mod/assignment/type/upload/assignment.class.php	20 Sep 2010 03:50:13 -0000
@@ -1025,6 +1025,8 @@
         $mform->addHelpButton('var4', 'trackdrafts', 'assignment');
         $mform->setDefault('var4', 1);
 
+        $course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
+        plagiarism_get_form_elements_module($mform, $course_context);
     }
 
     function portfolio_exportable() {
Index: course/modedit.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/modedit.php,v
retrieving revision 1.105
diff -u -r1.105 modedit.php
--- course/modedit.php	17 Sep 2010 20:36:49 -0000	1.105
+++ course/modedit.php	20 Sep 2010 03:50:10 -0000
@@ -29,6 +29,7 @@
 require_once($CFG->libdir.'/gradelib.php');
 require_once($CFG->libdir.'/completionlib.php');
 require_once($CFG->libdir.'/conditionlib.php');
+require_once($CFG->libdir.'/plagiarismlib.php');
 
 $add    = optional_param('add', '', PARAM_ALPHA);     // module name
 $update = optional_param('update', 0, PARAM_INT);
@@ -560,6 +561,7 @@
 
     rebuild_course_cache($course->id);
     grade_regrade_final_grades($course->id);
+    plagiarism_save_form_elements($fromform); //save plagiarism settings
 
     if (isset($fromform->submitbutton)) {
         redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");
Index: lang/en/plagiarism.php
===================================================================
RCS file: lang/en/plagiarism.php
diff -N lang/en/plagiarism.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ lang/en/plagiarism.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,9 @@
+<?php
+$string['availableplugins'] = 'Available plugins';
+$string['configplagiarismplugins'] = 'Please choose the plagiarism plugin you would like to configure';
+$string['enableplagiarism'] ='Enable plagiarism plugins';
+$string['configenableplagiarism'] = 'This will allow administrators to configure plagiarism plugins (if installed)';
+$string['manageplagiarism'] = 'Manage plagiarism plugins';
+$string['nopluginsinstalled'] = 'No plagiarism plugins are installed.';
+$string['plagiarism'] = 'Plagiarism prevention';
+$string['plagiarismsettings'] = 'Plagiarism settings';
Index: plagiarism/lib.php
===================================================================
RCS file: plagiarism/lib.php
diff -N plagiarism/lib.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plagiarism/lib.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,76 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * lib.php - Contains Plagiarism base class used by plugins.
+ *
+ * @since 2.0
+ * @package    moodlecore
+ * @subpackage plagiarism
+ * @copyright  2010 Dan Marsden http://danmarsden.com
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+if (!defined('MOODLE_INTERNAL')) {
+    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+}
+
+//dummy class - all plugins should be based off this.
+class plagiarism_plugin {
+    /**
+     * hook to allow plagiarism specific information to be displayed beside a submission 
+     * @param array  $linkarraycontains all relevant information for the plugin to generate a link
+     * @return string
+     * 
+     */
+    public function get_links($linkarray) {
+        return '';
+    }
+    /**
+     * hook to add plagiarism specific settings to a module settings page
+     * @param object $mform  - Moodle form
+     * @param object $context - current context
+     */
+    public function get_form_elements_module($mform, $context) {
+    }
+    /* hook to save plagiarism specific settings on a module settings page
+     * @param object $data - data from an mform submission.
+     */
+    public function save_form_elements($data) {
+    }
+    /**
+     * hook to allow a disclosure to be printed notifying users what will happen with their submission
+     * @param int $cmid - course module id
+     * @return string
+     */
+    public function print_disclosure($cmid) {
+    }
+    /**
+     * hook to allow status of submitted files to be updated - called on grading/report pages.
+     *
+     * @param object $course - full Course object
+     * @param object $cm - full cm object
+     */
+    public function update_status($course, $cm) {
+    }
+    /**
+     * hook for cron
+     *
+     */
+    public function plagiarism_cron() {
+    }
+}
\ No newline at end of file
Index: lib/plagiarismlib.php
===================================================================
RCS file: lib/plagiarismlib.php
diff -N lib/plagiarismlib.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ lib/plagiarismlib.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,170 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * plagiarismlib.php - Contains core Plagiarism related functions.
+ *
+ * @since 2.0
+ * @package    moodlecore
+ * @subpackage plagiarism
+ * @copyright  2010 Dan Marsden http://danmarsden.com
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+///// GENERIC PLAGIARISM FUNCTIONS ////////////////////////////////////////////////////
+
+if (!defined('MOODLE_INTERNAL')) {
+    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+}
+
+/**
+ * displays the similarity score and provides a link to the full report if allowed.
+ *
+ * @param object  $linkarray contains all relevant information for the plugin to generate a link
+ * @return string - url to allow login/viewing of a similarity report
+ */
+function plagiarism_get_links($linkarray) {
+    global $CFG;
+    if (empty($CFG->enableplagiarism)) {
+        return '';
+    }
+    $plagiarismplugins = plagiarism_load_available_plugins();
+    $output = '';
+    foreach($plagiarismplugins as $plugin => $dir) {
+        require_once($dir.'/lib.php');
+        $plagiarismclass = "plagiarism_plugin_$plugin";
+        $plagiarismplugin = new $plagiarismclass;
+        $output .= $plagiarismplugin->get_links($linkarray);
+    }
+    return $output;
+}
+
+/**
+ * saves/updates plagiarism settings from a modules config page - called by course/modedit.php
+ *
+ * @param object $data - form data
+ */
+function plagiarism_save_form_elements($data) {
+    global $CFG;
+    if (empty($CFG->enableplagiarism)) {
+        return '';
+    }
+    $plagiarismplugins = plagiarism_load_available_plugins();
+    foreach($plagiarismplugins as $plugin => $dir) {
+        require_once($dir.'/lib.php');
+        $plagiarismclass = "plagiarism_plugin_$plugin";
+        $plagiarismplugin = new $plagiarismclass;
+        $plagiarismplugin->save_form_elements($data);
+    }
+}
+
+/**
+ * adds the list of plagiarism settings to a form - called inside modules that have enabled plagiarism
+ *
+ * @param object $mform - Moodle form object
+ * @param object $context - context object
+ */
+function plagiarism_get_form_elements_module($mform, $context) {
+    global $CFG;
+    if (empty($CFG->enableplagiarism)) {
+        return '';
+    }
+    $plagiarismplugins = plagiarism_load_available_plugins();
+    foreach($plagiarismplugins as $plugin => $dir) {
+        require_once($dir.'/lib.php');
+        $plagiarismclass = "plagiarism_plugin_$plugin";
+        $plagiarismplugin = new $plagiarismclass;
+        $plagiarismplugin->get_form_elements_module($mform, $context);
+    }
+}
+/**
+ * updates the status of all files within a module
+ *
+ * @param object $course - full Course object
+ * @param object $cm - full cm object
+ */
+function plagiarism_update_status($course, $cm) {
+    global $CFG;
+    if (empty($CFG->enableplagiarism)) {
+        return '';
+    }
+    $plagiarismplugins = plagiarism_load_available_plugins();
+    foreach($plagiarismplugins as $plugin => $dir) {
+        require_once($dir.'/lib.php');
+        $plagiarismclass = "plagiarism_plugin_$plugin";
+        $plagiarismplugin = new $plagiarismclass;
+        $plagiarismplugin->update_status($course, $cm);
+    }
+}
+
+/**
+* Function that prints the student disclosure notifying that the files will be checked for plagiarism
+* @param integer $cmid - the cmid of this module
+*/
+function plagiarism_print_disclosure($cmid) {
+    global $CFG;
+    if (empty($CFG->enableplagiarism)) {
+        return '';
+    }
+    $plagiarismplugins = plagiarism_load_available_plugins();
+    foreach($plagiarismplugins as $plugin => $dir) {
+        require_once($dir.'/lib.php');
+        $plagiarismclass = "plagiarism_plugin_$plugin";
+        $plagiarismplugin = new $plagiarismclass;
+        $plagiarismplugin->print_disclosure($cmid);
+    }
+}
+/**
+ * used by admin/cron.php to get similarity scores from submitted files.
+ *
+ */
+function plagiarism_cron() {
+    global $CFG;
+    if (empty($CFG->enableplagiarism)) {
+        return '';
+    }
+    $plagiarismplugins = plagiarism_load_available_plugins();
+    foreach($plagiarismplugins as $plugin => $dir) {
+        require_once($dir.'/lib.php');
+        $plagiarismclass = "plagiarism_plugin_$plugin";
+        $plagiarismplugin = new $plagiarismclass;
+        $plagiarismplugin->cron();
+    }
+}
+/** 
+ * helper function - also loads lib file of plagiarism plugin
+ * @return array of available plugins
+ */
+function plagiarism_load_available_plugins() {
+    global $CFG;
+    if (empty($CFG->enableplagiarism)) {
+        return array();
+    }
+    $plagiarismplugins = get_plugin_list('plagiarism');
+    $availableplugins = array();
+    foreach($plagiarismplugins as $plugin => $dir) {
+        //check this plugin is enabled and a lib file exists.
+        if (get_config('plagiarism', $plugin."_use") && file_exists($dir."/lib.php")) {
+            require_once($dir.'/lib.php');
+            $plagiarismclass = "plagiarism_plugin_$plugin";
+            if (class_exists($plagiarismclass)) {
+                $availableplugins[$plugin] = $dir;
+            }
+        }
+    }
+    return $availableplugins;
+}
